package com.product.android.ui.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.nd.android.u.allcommon.R;
import com.product.android.business.headImage.HeadImageLoader;
import com.product.android.business.headImage.HeadImageLoader.ImageType;
import com.product.android.commonInterface.BaseCommonStruct;
import com.product.android.commonInterface.CIConst;
import com.product.android.commonInterface.CommonInterfaceManager;
import com.product.android.commonInterface.contact.RankInfo;

/**
 * ClassName:TopRankItemView
 * Function: TODO ADD FUNCTION
 * Reason:	 TODO ADD REASON
 * 
 * @author   HuangYK		
 * @version  
 * @since    Ver 1.3
 * @Date	 2013	2013-11-11		下午7:30:58
 *
 * @see 	 
 */
public class TopRankItemView extends RelativeLayout{
	
	public final static int FIRST_LINE_TYPE = 1;
	public final static int SECOND_LINE_TYPE = 2;
	public final static int OTHER_LINE_TYPE = 3;
	
	private Context mContext;
	
	private TopCropImageView mIvHead;
	private TextView mTvName;
	private TextView mTvNum;
	private BaseCommonStruct mParams = new BaseCommonStruct();

	public TopRankItemView(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
		mContext = context;
		init();
	}
	
	public TopRankItemView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		mContext = context;
		LayoutInflater.from(mContext).inflate(R.layout.top_rank_item_view, this, true);
		init();
	}	
	
	public void init(){
		mIvHead = (TopCropImageView) findViewById(R.id.ivhead);
		mTvName = (TextView) findViewById(R.id.tvname);
		mTvNum = (TextView) findViewById(R.id.tvnum);
		setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				mParams.lPara = (Long) v.getTag();
				mParams.obj1 = mContext;
				CommonInterfaceManager.INSTANCE.CommonInterfaceID(
						CIConst.WEIBO_MODELID,
						CIConst.WEIBO_ACTIVITY_TO_PROFILE_32101, mParams);
			}
		});
	}
	
	public void setData(RankInfo info, int screenWidth, int topType,
			ImageType showType) {
		if (info == null)
			return;
		this.setTag(info.uid);
		mTvName.setText(info.userName);
		mTvNum.setText("" + info.total);
		if (topType == TopRankView.SECRETLOVE_RANK) {
			mTvNum.setCompoundDrawablesWithIntrinsicBounds(
					null,
					null,
					getResources().getDrawable(
							R.drawable.wbflow_toprankactivity_heart), null);
		} else {
			// 需要有花图片
			mTvNum.setCompoundDrawablesWithIntrinsicBounds(null, null,
					getResources().getDrawable(R.drawable.flower_icon), null);
		}
		mTvNum.setCompoundDrawablePadding(3);

		HeadImageLoader.displayRankImage(screenWidth, info.uid,
				info.sysAvatarId, mIvHead, showType);
	}
}
